% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
%   http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.
-module(test_httpc_profile_id_server).

%% Include files
-include_lib("eunit/include/eunit.hrl").

-export([]).

setup() ->
    T = ets:new(myets,[named_table,public]), 
	ets:insert(T, {number_of_ids, 0}),
	ets:insert(T, {available_ids, []}),
    nimbula_httpc_profile_id_server:start_link(T). 

cleanup(_) ->
	ets:delete(myets).

get_first_profile_id_test_() ->
    {setup,
     fun setup/0,
     fun cleanup/1,
     fun () ->
	     '1' = nimbula_httpc_profile_id_server:get_profile_id()
     end}.

get_three_profile_ids_test_() ->
    {setup,
     fun setup/0,
     fun cleanup/1,
     fun () ->
	     '1' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '2' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '3' = nimbula_httpc_profile_id_server:get_profile_id()
     end}.


restore_profile_id_test_() ->
    {setup,
     fun setup/0,
     fun cleanup/1,
     fun () ->
	     '1' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '2' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '3' = nimbula_httpc_profile_id_server:get_profile_id(),
		 ok = nimbula_httpc_profile_id_server:restore_profile_id('2'),
	     '2' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '4' = nimbula_httpc_profile_id_server:get_profile_id()
     end}.

restore_multiple_profile_id_test_() ->
    {setup,
     fun setup/0,
     fun cleanup/1,
     fun () ->
	     '1' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '2' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '3' = nimbula_httpc_profile_id_server:get_profile_id(),
		 ok = nimbula_httpc_profile_id_server:restore_profile_id('2'),
		 ok = nimbula_httpc_profile_id_server:restore_profile_id('1'),
	     '1' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '2' = nimbula_httpc_profile_id_server:get_profile_id(),
	     '4' = nimbula_httpc_profile_id_server:get_profile_id()
     end}.
